﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using static System.Net.Mime.MediaTypeNames;

namespace RS.ZhaoXiWidgets.Controls
{
    public class ZXCustomNumber : ContentControl
    {
        static ZXCustomNumber()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ZXCustomNumber), new FrameworkPropertyMetadata(typeof(ZXCustomNumber)));
        }




        public ObservableCollection<string> NumberList
        {
            get { return (ObservableCollection<string>)GetValue(NumberListProperty); }
            set { SetValue(NumberListProperty, value); }
        }

        public static readonly DependencyProperty NumberListProperty =
            DependencyProperty.Register("NumberList", typeof(ObservableCollection<string>), typeof(ZXCustomNumber), new PropertyMetadata(null));




        public int NumberInput
        {
            get { return (int)GetValue(NumberInputProperty); }
            set { SetValue(NumberInputProperty, value); }
        }

        public static readonly DependencyProperty NumberInputProperty =
            DependencyProperty.Register("NumberInput", typeof(int), typeof(ZXCustomNumber), new PropertyMetadata(0, OnNumberInputPropertyChanged));

        private static void OnNumberInputPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var zxCustomNumber = d as ZXCustomNumber;
            string bumberString = zxCustomNumber.NumberInput.ToString();
            if (bumberString.Count() == 1)
            {
                bumberString = bumberString.PadLeft(3, '0');
            }
            else if (bumberString.Count() == 2)
            {
                bumberString = bumberString.PadLeft(3, '0');
            }
            else if (bumberString.Count() == 3)
            {
                bumberString = bumberString.PadLeft(4, '0');
            }
            var resultList = bumberString.ToCharArray().Select(c => c.ToString()).ToList();
            zxCustomNumber.NumberList = new ObservableCollection<string>(resultList);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
        }

    }
}
